using {ConfigService} from '..//srv/config-service';

annotate ConfigService.Options with @odata.draft.enabled;

annotate ConfigService.Options with @(UI : {
  SelectionFields     : [
    type,
    createdAt,
    createdBy
  ],
  LineItem            : [
    {Value : group, },
    {Value : code, },
    {Value : name, },
    {Value : value, },
    {
      $Type  : 'UI.DataFieldForAction',
      Label  : 'Update Value',
      Action : 'ConfigService.updateValue',
    },
    {
      $Type  : 'UI.DataFieldForAction',
      Label  : 'Direct Create',
      Action : 'ConfigService.createSingleOption',
    }
  ],
  HeaderInfo          : {
    TypeName       : 'Option',
    TypeNamePlural : 'Options',
    Title          : {Value : code},
    Description    : {Value : name}
  },
  Facets              : [{
    $Type  : 'UI.ReferenceFacet',
    Label  : '{i18n>Details}',
    Target : '@UI.FieldGroup#Details'
  }],
  FieldGroup #Details : {Data : [
    {Value : type, },
    {Value : group, },
    {Value : value, }
  ]}
}, );

annotate ConfigService.Options with {
  ID        @UI.Hidden       : true;
  validFrom @UI.Hidden       : true;
  createdAt @UI.HiddenFilter : false;
  createdBy @UI.HiddenFilter : false;
  type      @title           : 'Type';
  group     @title           : 'Group';
  code      @title           : 'Code';
  name      @title           : 'Name';
  value     @title           : 'Value'
};

// No need for popover
// annotate ConfigService.Options with actions {
//     updateValue @(Common.IsActionCritical : false)
// };

// annotate ConfigService.createSingleOption with @(Common.IsActionCritical : false);

annotate ConfigService.Options actions {
  createSingleOption @(
    cds.odata.bindingparameter.name : '_it',
    cds.odata.bindingparameter.collection,
    Common.SideEffects              : {TargetEntities : [_it]}
  );
};
